/**
 * @param {string} path
 * @returns {Boolean}
 */
export function isExternal(path) {
  return /^(https?:|mailto:|tel:)/.test(path)
}

/**
 * @param {string} str
 * @returns {Boolean}
 */
export function validUsername(str) {
  const valid_map = ['admin', 'hr','manager','employee']
  return valid_map.indexOf(str.trim()) >= 0
}


//手机号校验
export function checkPhone(rule, value, callback){
	 // let phoneReg = /(^1[3|4|5|6|7|8|9]\d{9}$)|(^09\d{8}$)/;
	 if (value == "") {
	   callback(new Error("手机号不能为空"));
	 } else if (!/^1(3|4|5|6|7|8)\d{9}$/.test(value)) {
	   callback(new Error("手机号不合法!"));
	 } else {
	   callback();
	 }
}

//邮箱校验
export function checkEmail(rule, value, callback) {
    const reg = /^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/;
    const email = reg.test(value);
    if (!email) {
      callback(new Error("邮箱格式不合法"));
    } else {
      callback();
    }
};

//身份证号校验
export function checkIDCard (rule, value, callback) {
  if (!value) {
    return new Error("请输入身份证号)"); 
  } else {
    const reg = /^\d{6}(18|19|20)?\d{2}(0[1-9]|1[0-2])(([0-2][1-9])|10|20|30|31)\d{3}(\d|X|x)$/;
    const card = reg.test(value);
    if (!card) {
      callback(new Error("身份证格式不合法"));
    } else {
      callback();
    }
  }
}